package com.chenjun.common.util;

import java.util.Calendar;

public class CardNo2AgeUtil {

	
	
	public static int cardNo2Age(String cardNo) throws Exception{
		// 获取出生日期    
        String birthday = cardNo.substring(6, 14);    
          
        //获取当前年月日
        //SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyyMMdd"); 
        Calendar c = Calendar.getInstance(); 
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH)+1;
        int day = c.get(Calendar.DAY_OF_MONTH);
        
        //获取生日的年月日
        int myYear = Integer.parseInt(birthday.substring(0,4));
        int myMonth = Integer.parseInt(birthday.substring(4,6));
        int myDay = Integer.parseInt(birthday.substring(6,8));
        
        //当前月大于我的月份  说明已经过了生日了
        if(month>myMonth){
        	return year - myYear;
        }
      //当前月大于我的月份  说明还没生日
        if(month<myMonth){
        	return year - myYear - 1;
        }
      //当前月等于我的月份  比较日
        if(month==myMonth){
        	if(day>=myDay){
        		return year - myYear;
        	}else{
        		return year - myYear - 1;
        	}
        }
        return 0;
	}
	
	public static String cardNo2Star(String cardNo) throws Exception{
		String strValue = "";
		// 获取出生日期    
        String birthday = cardNo.substring(6, 14); 
		//int year = Integer.parseInt(cardNo.substring(0,4));
        int month = Integer.parseInt(birthday.substring(4,6));
        int day = Integer.parseInt(birthday.substring(6,8));
		if ((month == 1 && day >= 20) || (month == 2 && day <= 18)) {
			strValue = "水瓶座";
			} else if ((month == 2 && day >= 19) || (month == 3 && day <= 20)) {
			strValue = "双鱼座";
			} else if ((month == 3 && day > 20) || (month == 4 && day <= 19)) {
			strValue = "白羊座";
			} else if ((month == 4 && day >= 20) || (month == 5 && day <= 20)) {
			strValue = "金牛座";
			} else if ((month == 5 && day >= 21) || (month == 6 && day <= 21)) {
			strValue = "双子座";
			} else if ((month == 6 && day > 21) || (month == 7 && day <= 22)) {
			strValue = "巨蟹座";
			} else if ((month == 7 && day > 22) || (month == 8 && day <= 22)) {
			strValue = "狮子座";
			} else if ((month == 8 && day >= 23) || (month == 9 && day <= 22)) {
			strValue = "处女座";
			} else if ((month == 9 && day >= 23) || (month == 10 && day <= 23)) {
			strValue = "天秤座";
			} else if ((month == 10 && day > 23) || (month == 11 && day <= 22)) {
			strValue = "天蝎座";
			} else if ((month == 11 && day > 22) || (month == 12 && day <= 21)) {
			strValue = "射手座";
			} else if ((month == 12 && day > 21) || (month == 1 && day <= 19)) {
			strValue = "魔羯座";
			}
		return strValue;
	}
	
	public static void main(String[] args) throws Exception {
		//int age = cardNo2Age("320283199006026533");
		//System.out.println(age);
		
		String star = cardNo2Star("320283199006026533");
		System.out.println(star);
	}
}
